package top.houry.test;

import io.grpc.Server;
import io.grpc.ServerBuilder;
import io.grpc.stub.StreamObserver;
import top.houry.grpc.proto.OpenAPIGrpc;
import top.houry.grpc.proto.TestGrpc;

public class ServerStreamingServerGrpc {
    public static void main(String[] args) throws Exception {
        Server server = ServerBuilder.forPort(9999).addService(new GrpcServerStreamingService()).build();
        server.start();
        server.awaitTermination();
    }
}


class GrpcServerStreamingService extends OpenAPIGrpc.OpenAPIImplBase {

    @Override
    public void serverStreaming(TestGrpc.Request request, StreamObserver<TestGrpc.Response> responseObserver) {
        for (int i = 0; i < 5; i++) {
            TestGrpc.Response response = TestGrpc.Response.newBuilder().setMessage(System.currentTimeMillis() + " 服务端消息 " + i).build();
            responseObserver.onNext(response);
        }
        responseObserver.onCompleted();
    }
}